package com.indusfo.spc.client.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.indusfo.spc.client.mapper.ClientSpcDeteDetailMapper;
import com.indusfo.spc.client.mapper.ClientSpcOrderMapper;
import com.indusfo.spc.client.pojo.ClientSpcDeteDetail;
import com.indusfo.spc.client.service.ClientSpcDeteDetailService;
import com.indusfo.spc.exception.ModifyFailedException;

/**
 * 客户端检测值
 * 
 * @author zhengd
 */
@Service
public class ClientSpcDeteDetailServiceImpl implements ClientSpcDeteDetailService {
	@Autowired
	ClientSpcDeteDetailMapper clientSpcDeteDetailMapper;
	@Autowired
	ClientSpcOrderMapper clientSpcOrderMapper;

	@Override
	@Transactional
	public String insertClientSpcDeteDetail(List<ClientSpcDeteDetail> clientSpcDeteDetails) {
		// 保存检测值
		Integer count = clientSpcDeteDetailMapper.insertClientSpcDeteDetail(clientSpcDeteDetails);
		if (count != clientSpcDeteDetails.size()) {
			throw new ModifyFailedException("新增检测值失败！");
		}
		// 更新检测单状态为检测中
		count = clientSpcOrderMapper.updateDeteStateBySpcDeteId(clientSpcDeteDetails.get(0).getSpcDeteId());
		if (count == 0) {
			throw new ModifyFailedException("修改检测单状态失败！");
		}
		return "保存成功！";
	}

}
